﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;


namespace ProjetoDalc.cs
{
    public class LoginDalc
    {
        public bool verificaLoginHome(string login, string senha)
        {
            using (SqlConnection conexao = Connection.CriarConexao())
            {
                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();

                command.Connection = conexao;
                command.CommandText = "SELECT USUARIO FROM CADASTRO_LOGIN WHERE USUARIO = @NomeUsario AND SENHA = @Senha;";
                command.Parameters.AddWithValue("@NomeUsario", login);
                command.Parameters.AddWithValue("@Senha", senha);

                conexao.Open();

                object usuario = command.ExecuteScalar();

                conexao.Close();

                if (usuario == null)
                    return false;
                else
                    return true;
            }
        }

        public bool verificaDataDemissao(string login, string senha) // PAULA
        {
            using (SqlConnection conexao = Connection.CriarConexao())
            {

                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();
                command.Connection = conexao;

                command.CommandText = "SELECT FUNCIONARIO_SAIDA FROM CADASTRO_LOGIN AS CL INNER JOIN FUNCIONARIO AS FUN ON (FUN.CADASTRO_LOGIN_ID = CL.CADASTRO_LOGIN_ID) WHERE USUARIO = @Usuario AND SENHA = @SenhaUsuario ;";
                command.Parameters.AddWithValue("@Usuario", login);
                command.Parameters.AddWithValue("@SenhaUsuario", senha);
                conexao.Open();
                DateTime funcionario_saida;
                object valorObject = command.ExecuteScalar();

                if ((valorObject == null) || (valorObject == DBNull.Value))
                    return true;
                else
                {
                    funcionario_saida = (DateTime)command.ExecuteScalar();
                    if (funcionario_saida >= DateTime.Now)
                        return true;
                    else
                        return false;
                }
            }
        }

        public string retornaTipoFuncionario(string login, string senha)
        {
            using (SqlConnection conexao = Connection.CriarConexao())
            {
                SqlCommand command = new SqlCommand();
                SqlDataAdapter adapter = new SqlDataAdapter();

                command.Connection = conexao;
                command.CommandText = "SELECT TIPO FROM CADASTRO_LOGIN WHERE USUARIO = @Usuario AND SENHA = @SenhaUsuario;";
                command.Parameters.AddWithValue("@Usuario", login);
                command.Parameters.AddWithValue("@SenhaUsuario", senha);

                conexao.Open();
                string usuario = (string)command.ExecuteScalar();
                conexao.Close();
                return usuario;
            
            }
        }
    }
}
